import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

 const store = new Vuex.Store({
  state: {
    products:[
      {name:"马云",price:200},
      {name:"马化腾",price:140},
      {name:"马冬梅",price:20},
      {name:"马蓉",price:10},
    ]
  },
  getters:{
    saleProducts:(state) => {
      return 'this is 公共的方法'
    }
  },
  mutations: {
    reducePrice:state => {
      state.products.forEach(product => {
        product.price -= 1
      })
    }
  },
  actions: {
    reducePrice:(context) => {
      setTimeout(()=>{
        context.commit("reducePrice")
      },2000)
    }
  }
})
export default store